package pl.com.sjap.agenci;

import CLIPSJNI.Environment;
import CLIPSJNI.MultifieldValue;

public class MyCar {
	
	private String owner;
	private String typeOfCar;
	private String action;
	
	public MyCar(String owner, String typeOfCar, String action) {
		super();
		this.owner = owner;
		this.typeOfCar = typeOfCar;
		this.action = action;
		
	}
	
	public String addAction(){
		return "(akcja (typ_akcji "+action+" ))";
	}
	public String changeAction(String action, Environment clipse){
		this.action = action;
		clipse.assertString(this.addAction());
		return "(akcja (typ_akcji "+action+" ))";
	}
	public String addCar(){
		
		return "(samochod (posiadacz "+owner+") (typ "+typeOfCar+"))";
	}
	public String getAboutCar(Environment clipse){
		MultifieldValue carOwner = (MultifieldValue) clipse
				.eval("(find-all-facts ((?c samochod)) TRUE)");
		//changeAction("kontrola_drogowa", clipse);
		clipse.assertString(addAction());
		try {
			this.setOwner(carOwner.get(0).getFactSlot("posiadacz").toString());
			this.setTypeOfCar(carOwner.get(0).getFactSlot("typ").toString());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "samochod[(posiadacz " +owner+ ") (typ "+typeOfCar+") ]";
	}
	
	public String getAboutAction(Environment clipse){

		
		MultifieldValue carOwner = (MultifieldValue) clipse
				.eval("(find-all-facts ((?f akcja)) TRUE)");
		try {
			//clipse.assertString(this.addAction());
			this.setAction(carOwner.get(0).getFactSlot("typ_akcji").toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "akcja[(typ_akcji "+this.action+" )]";
	}
	
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public String getTypeOfCar() {
		return typeOfCar;
	}
	public void setTypeOfCar(String typeOfCar) {
		this.typeOfCar = typeOfCar;
	}
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	@Override
	public String toString() {
		return "MyCar [owner=" + owner + ", typeOfCar=" + typeOfCar
				+ ", action=" + action + ", getOwner()=" + getOwner()
				+ ", getTypeOfCar()=" + getTypeOfCar() + ", getClass()="
				+ getClass() + ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}

}
